package com.wyw.log.learning.controller;

import com.wyw.log.learning.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Title
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2024/3/28 18:11
 * Update History:
 * Author        Time            Content
 */
@RestController
@Slf4j
public class TestController {
    static ExecutorService service = Executors.newFixedThreadPool(2000);

    @Autowired
    private TestService testService;
    @GetMapping("/hello")
    public String hello(){
        service.submit(
                new Runnable() {
                    @Override
                    public void run() {
//                        log.info("123456");
                    }
                }
        );
        return "hello";
    }
    @GetMapping("/error")
    public String error(@RequestParam String error){
        Assert.notNull(error, "必传");
//        throw new RuntimeException();
        try{
            throw new RuntimeException();
        } catch(Exception ex){
            log.error("异常", ex);
        }
        return error;
    }
    @GetMapping("test")
    public String test(){
        log.info("123456");
        testService.asyncImportGoods("12300");
        log.info("你好");
        return "hello";
    }
}
